﻿//诊疗记录相关
$(function () {
    $('#btnSearch').click(function () {
        BindList(1);
    });
    $('#btnAdd').click(function () {
        edit(0);
    });
    $(document).keyup(function (event) {
        if (event.keyCode == 13) {
            initTable(1);
        }
    });
    BindList(1);
});

function BindList(pageNumber) {
    var queryData = {
        Name: $("#txtName").val()
    }
    $("#maingrid").ligerGrid({
        height: '100%',
        //data: {
        //    "Total":6, "Rows": [
        //        { "ID": 2, "Name": "心电图时间", "ParentId": 0, "Level": 0, "Sort": "已出心电图，心电图异常", "UpdateUserId": null, "UpdateTime": "2019-02-26 17:53:34", "CreateUserId": "1", "CreateTime": "2018-12-17 17:10:58" },
        //        { "ID": 13, "Name": "心内科医生会诊", "ParentId": 0, "Level": 0, "Sort": "会诊完毕，记录完毕", "UpdateUserId": null, "UpdateTime": "2019-06-20 14:41:20", "CreateUserId": "1", "CreateTime": "2019-03-27 14:30:56" },
        //        { "ID": 14, "Name": "导管室时间", "ParentId": 0, "Level": 0, "Sort": "导管室检查，无异常", "UpdateUserId": null, "UpdateTime": null, "CreateUserId": "1", "CreateTime": "2019-06-13 11:40:40" },
        //     ]
        //},
        url: '/ChestPainCenter/DisRecord/Search?ram=' + new Date().getMilliseconds(),
        parms: queryData,
        rownumbers: false,
        heightDiff: -5,
        columns: [
            {
                display: '诊疗记录编码', name: 'code', maxWidth: 100
            },
        {
            display: '诊疗记录名称', name: 'name', maxWidth: 200
        },
         { display: '描述', name: 'zl_desc', maxWidth: 150 },

         {
             display: '操作者', name: 'create_user', maxWidth: 150
         },


        {
            display: '创建时间', name: 'create_time', maxWidth: 150
        },


        {
            display: '操作', name: 'Name', render: function (row) {
                var html = '';
                html += '<a href="javascript:edit(' + row.Id + ')">' + "编辑" + '</a>';
                html += "&nbsp;&nbsp;&nbsp;";
                html += '<a href="javascript:del(' + row.Id + ')">' + "删除" + '</a>';
                return html;
            }
        }
        ]
    });
}

//添加/编辑
function edit(id) {
    var tit = (id > 0) ? "编辑" : "添加";
    $.ligerDialog.open({
        height: 350,
        width: 450,
        title: tit,
        data: { Id: id },
        url: '/ChestPainCenter/DisRecord/Edit?id=' + id,
        showMax: false,
        showToggle: false,
        showMin: false,
        isResize: false,
        slide: false,
        buttons: [{
            text: '回调函数', onclick: function (i, d) {
                $("#btnSearch").click();
            }
        }],
        cls: "closeCls"
    });
    $(".l-dialog-buttons").hide();
}
$(document).on("click", ".closeCls", function () {
    $("#btnSearch").click();
});

//删除
function del(id) {
    $.ligerDialog.confirm('确定删除？', function (value) {
        if (value) {
            var url = "/ChestPainCenter/DisRecord/Delete";
            $.ajax({
                url: url,
                type: "POST",
                cache: false,
                data: { id: id },
                success: function (data) {
                    var d = $.parseJSON(data);
                    if (d.Result == 1) {
                        $.ligerDialog.success("删除成功");
                        $('#btnSearch').click();
                    }
                    else if (d.Result == 0) {
                        $.ligerDialog.error(d.Body);
                    }
                    else {
                        $.ligerDialog.error("程序错误");
                    }
                },
                error: function () {
                    $.ligerDialog.error("程序错误");
                }
            });
        }
    });
}